package usecase

import (
	"context"

	"github.com/go-kratos/kratos-layout/internal/domain"
	"github.com/go-kratos/kratos-layout/internal/model"
)

type GreeterUsecase struct {
	greeter model.GreeterModel
}

func NewGreeterUsecase(greeter model.GreeterModel) *GreeterUsecase {
	return &GreeterUsecase{
		greeter: greeter,
	}
}

func (u *GreeterUsecase) CreateGreeter(ctx context.Context, req *domain.Greeter) (*domain.Greeter, error) {
	data, err := u.greeter.Save(ctx, &model.Greeter{Hello: req.Hello})
	if err != nil {
		return nil, err
	}
	return &domain.Greeter{
		Hello: data.Hello,
	}, nil
}
